<?php 
class EmployeeController extends Henry_Controller_Action
{
 
    public function init()
    {
        parent::init();
    }
    private function filterdata($params)
    {
    	$data = array();
    	if (empty($params)) return;
    	foreach ($params as $key=>$item)
    	{
    		if((stristr($key,"employee_")!== false) && !empty($item))
			{
				$data[$key]= $item;
			}
    	}	
    	return $data;
    }
    public function listemployeeAction()
    {    
    	$empModelOb = new Default_Model_Employee();
    	$paginator = Zend_Paginator::factory($empModelOb->listEmployee());    	
    	$paginator->setCurrentPageNumber($this->_getParam("page")); // Note: For this to work of course, your URL must be something like this: http://localhost:8888/index/index/page/1 <- meaning we are currently on page one, and pass that value into the "setCurrentPageNumber"
		$paginator->setItemCountPerPage(20);
		$paginator->setPageRange(10);
		$this->view->paginator = $paginator;
		$this->view->link = $this->view->baseUrl()."/employee/";
    }
    public function indexAction()
    {    	
    	$requestOb = $this->getRequest(); 
       	$params = $requestOb->getParams();
        if($requestOb->isPost())
        {        	
        	$data=$this->filterdata($params);    
        	//Henry_TestUtil::printDie($data);   
        	$validtor = new Default_View_Filter_CheckEmployee($data);
        	if ($validtor->isValid())
        	{
		       $empModelOb = new Default_Model_Employee();
		       if($empModelOb->addEmployee($data))
		       {
		       		$this->view->assign('message',array('Save successful'));
		       }
        	}
        	else
        	{        		
        		$this->view->assign('message',$validtor->getMessages());
        		$this->view->cusItem = $data;
        	}
        }	        
        $this->view->assign('currentPage',$params['page']);
    }	
	public function deleteAction()
	{
		$empModelOb = new Default_Model_Employee();
		$id = $this->_getParam('id');
		if ($empModelOb->delEmployee($id))
		{
			$this->_redirect("employee");
		}
	}
	public function updateAction()
	{
		$id = $this->_getParam('id');
        $empModelOb = new Default_Model_Employee();		
		$requestOb = $this->getRequest();       
		$params = $requestOb->getParams();
		if($requestOb->isPost())
        {        	
       		$data=$this->filterdata($params);  
        	$validtor = new Default_View_Filter_CheckEmployee($data);
        	if ($validtor->isValid())
        	{
		       if($empModelOb->updateEmployee($id,$data))
		       {
		       		$this->view->assign('message',array('Update successful'));
		       }
		       else
		       {
		       		$this->view->assign('message',array('Employee infomation not change'));
		       }
        	}
        	else
        	{        		
        		$this->view->assign('message',$validtor->getMessages());
        	}
        }	   
        $this->view->cusItem = $empModelOb->getEmployee($id);     
        $this->view->assign('currentPage',$params['page']);
	}
	public function listEmployeeCalenderAction()
	{
		
	}
}

?>